package org.jeecg.modules.demo.seal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.demo.seal.entity.Seal;
import org.jeecg.modules.demo.seal.entity.SealTime;

import java.util.Date;
import java.util.List;

@Mapper
public interface SealMapper extends BaseMapper<Seal> {


    @Select("select ORG_CODE from SYS_USER where USERNAME = #{userid}")
    String getOrgCode(String userid);

    @Select("select * from GC_SEAL_TIME")
    SealTime getStartTime();



    @Update("update GC_SEAL set SEAL_STATUS = 0, UNBLOCK_TIME = time where ID = id")
    void unblock(String id, String time);

    @Select("select * from GC_SEAL_TIME")
    SealTime getSealTime();

    @Update("update GC_SEAL_TIME set START_TIME = #{sealTime.startTime},END_TIME = #{sealTime.endTime} where ID = #{sealTime.id}")
    void updataSealTime(@Param("sealTime") SealTime sealTime);

    @Select("select * from GC_SEAL where CAR_ID = #{carId} and UNBLOCK_TIME >= #{startTime} and UNBLOCK_TIME <= #{endTime}")
    Seal getByCarId(Integer carId, Date startTime, Date endTime);

    @Update("update GC_SEAL set CAR_ID = #{seal.carId},CAR_KEY = #{seal.carKey},SEAL_STATUS = #{seal.sealStatus},SEAL_IMG = #{seal.sealImg},POSITION = #{seal.position},SEAL_TIME = #{seal.sealTime},UNBLOCK_TIME = #{seal.unblockTime},REASON = #{seal.reason},DEPART_ID = #{seal.departId} where ID = #{seal.id}")
    void updateSealById(@Param("seal") Seal seal);
}
